/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOLSCOREDBESTOF_H
#define BOLSCOREDBESTOF_H

#include <deque>

#include "hasmetascore.h"

namespace bol {

/**
  a list of n (maximum) object implementing HasScore (obviously with the same descriptor)
  Only the n best one are kept;
   * values stored in the deque are sorted (best in front)

  @author Alexandre Masselot,GeneBio,http://www.genebio.com, <alexandre.masselot@gmail.com>
 */
  class ScoredBestOf:deque<HasMetaScorePtr>{
    private:
      int m_max;
      deque<HasMetaScorePtr>::iterator insertPos(const HasMetaScorePtr& scored);
      MetaScoreDescriptor const* m_descriptor;
    public:
      /**
     * max default value is set to 10
       */
      ScoredBestOf(){
        m_descriptor=NULL;
        m_max=10;
      }
      /**
       * @param max the maximum number of object to be kept;
       */
      ScoredBestOf(const int max){
        m_descriptor=NULL;
        m_max=max;
      }

      ~ScoredBestOf();

      /**
       * add an object with a MetaScore, i.e. will keep if it is within the max best object
       * @param scored
       * @return
       */
      bool add(const HasMetaScorePtr& scored);
      
      void setMax(int theValue) {
        m_max = theValue;
      }
  

      int max() const {
        return m_max;
      }
  
      friend ostream& operator<<(ostream& out, const ScoredBestOf& bestof);
  };

}

#endif
